<?php

namespace Pinenut\Model2;

/**
 * Контейнер для работы с модификаторами
 * 
 * @author Kosh
 *        
 */
class Updaters implements \ArrayAccess, \Iterator, \Countable {
	/**
	 *
	 * @return \Pinenut\Model2\Updater[]
	 */
	protected $_container = array ();
	
	/**
	 *
	 * @return \Pinenut\Model2\Updater
	 */
	function getFirstCloned() {
		$updater = reset ( $this->_container );
		// echo "clone:<pre>";print_r($updater);echo "</pre>/clone<br>";
		return clone $updater;
	}
	
	// ArrayAccess
	public function offsetSet($offset, $value) {
		// так добавлять низя
		if (is_null ( $offset )) {
			$this->_container [] = $value;
		} else {
			$this->_container [( string ) $offset] = $value;
		}
	}
	public function offsetExists($offset) {
		return isset ( $this->_container [( string ) $offset] );
	}
	public function offsetUnset($offset) {
		unset ( $this->_container [( string ) $offset] );
	}
	public function offsetGet($offset) {
		if (isset ( $this->_container [( string ) $offset] )) {
			return $this->_container [( string ) $offset];
		}
	}
	function rewind() {
		return reset ( $this->_container );
	}
	function current() {
		return current ( $this->_container );
	}
	function key() {
		return key ( $this->_container );
	}
	function next() {
		return next ( $this->_container );
	}
	function valid() {
		return key ( $this->_container ) !== null;
	}
	public function count() {
		return count ( $this->_container );
	}
}